package com.csy.admin.util;

import com.sun.org.apache.regexp.internal.RE;

import java.util.HashMap;
import java.util.Map;

/**
 * 类名:结果返回类
 * Created by CSY on 2018/9/3.
 */
public class Result extends HashMap<String, Object>{
    private static final long serialVersionUID = 1L;

    public Result(){
        put("code",200);
        put("msg","success");
    }

    /**
     * 成功
     * @param msg 返回自定义信息
     * @return
     */
    public static Result ok(String msg){
        Result result = new Result();
        result.put("msg",msg);
        return result;
    }

    /**
     * 成功
     * @param map 返回实体
     * @return
     */
    public static Result ok(Map<String,Object> map){
        Result result = new Result();
        result.putAll(map);
        return result;
    }

    /**
     * 成功
     * @return
     */
    public static Result ok(){
        return new Result();
    }

    /**
     * 错误
     * @param code 错误代码
     * @param msg 错误信息
     * @return
     */
    public static Result error(int code,String msg){
        Result result = new Result();
        result.put("code",code);
        result.put("msg",msg);
        return result;
    }

    /**
     * 错误
     * @param msg 错误信息
     * @return
     */
    public static Result error(String msg){
        Result result = new Result();
        result.put("code",500);
        result.put("msg",msg);
        return result;
    }

    /**
     * 错误
     * @return
     */
    public static Result error(){
        return error(500,"系统出错，请联系管理员");
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
